<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>

        <textarea placeholder="请在此输入要bb的内容(不超过120字)" maxlength="120"></textarea>
        <mt-button type="primary" size="large">发表评论</mt-button>
        <div class="cmt-list" v-for="(item,i) in comment_list" :key="item.id + '-label'">
            <div class="cmt-item">
                <div class="cmt-title">
                    第{{ i+1 }}楼&nbsp;&nbsp;{{ item.user_name }}&nbsp;&nbsp;发表时间：{{ item.add_time | dateFormat }}
                </div>
                <div class="cmt-body">
                    {{ item.content }}
                </div>
            </div>
        </div>
        <mt-button type="danger" size="large" plain>加载更多</mt-button>
    </div>
</template>

<script>
import { Toast } from 'mint-ui'

export default {
    data(){
        return {
            comment_list:[]
        }
    },
    created(){
        this.getComment()
    },
    methods:{
        getComment(){
            this.$http.get('json/comments/' + this.id+ ".json").then(reslut => {
                if(reslut.body.length > 0 ){
                    console.log('asdas')
                    this.comment_list = reslut.body
                    this.comment_list.forEach((item,index) => {
                        item.add_time = Date.now()
                    })
                }else{
                    Toast('数据加载失败')
                }
            })
        }
    },
    props:["id"]
}
</script>

<style lang="less" scoped>
    .cmt-container{
        h3{
            font-size: 16px;
        }

        textarea{
            font-size: 13px;
            height: 85px;
            margin: 0;
        }

        .cmt-list{
            font-size: 13px;
            .cmt-item{}

            .cmt-title{
                line-height: 35px;
            }

            .cmt-body{
                line-height: 35px;
                text-indent: 2em;
            }
        }
    }
</style>
